package com.anis.jpa.medical.model;

import java.io.Serializable;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 * The persistent class for the patient database table.
 * 
 */
@Entity
@Table(name = "patient")
@NamedQuery(name = "Patient.findAll", query = "SELECT p FROM Patient p")
public class Patient implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.TABLE)
	@Column(name = "IDPATIENT")
	private String idpatient;

	@Temporal(TemporalType.DATE)
	@Column(name = "BIRTHDAY")
	private Date birthday;

	@Temporal(TemporalType.DATE)
	@Column(name = "CREATIONDATE")
	private Date creationdate;

	@Column(name = "PATIENTADDRESS")
	private String patientaddress;

	@Lob
	@Column(name = "PATIENTIMAGE")
	private byte[] patientimage;

	@Column(name = "PATIENTLASTNAME")
	private String patientlastname;

	@Column(name = "PATIENTNAME")
	private String patientname;

	@Column(name = "PATIENTSEX")
	private String patientsex;

	@Column(name = "PATIENTTITLE")
	private String patienttitle;

	@Column(name = "PHONE")
	private int phone;

	@Column(name = "USEFULNOTES")
	private String usefullNotes;

	@Column(name = "NUM_MATR")
	private long numMatr;

	@Column(name = "TYPE")
	private String type;

	@Temporal(TemporalType.DATE)
	@Column(name = "VALIDITY_DATE")
	private Date validityDate;

	@Temporal(TemporalType.DATE)
	@Column(name = "RDVDATE")
	private Date rdvdate;

	// bi-directional many-to-one association to Medical Report
	@OneToMany(mappedBy = "patient", fetch = FetchType.EAGER)
	private List<MedicalReport> radioreports;

	public Patient() {
	}

	public Patient(String patientName2, String lastName, Integer patientPhone,
			Date patientBirthDay, Date creationdat, String title,
			String patientGender, String patientAddress2,
			ArrayList<MedicalReport> listOfRadioReports) {
		setPatientaddress(patientAddress2);
		setPatientlastname(lastName);
		setPatientname(patientName2);
		setPatientCreationdate(creationdat);
		setPatientsex(patientGender);
		setPatienttitle(title);
		setPatientBirthday(patientBirthDay);
		setPhone(patientPhone);
		setMedicalReports(listOfRadioReports);

	}


	public String getIdpatient() {
		return this.idpatient;
	}

	public void setIdpatient(String idpatient) {
		this.idpatient = idpatient;
	}

	public Date getBirthDay() {
		return this.birthday;
	}

	public void setPatientBirthday(Date birthDay) {
		this.birthday = birthDay;
	}

	public Date getPatientCreationdate() {
		return this.creationdate;
	}

	public void setPatientCreationdate(Date creationdate) {
		this.creationdate = creationdate;
	}

	public String getPatientaddress() {
		return this.patientaddress;
	}

	public void setPatientaddress(String patientaddress) {
		this.patientaddress = patientaddress;
	}

	public byte[] getPatientimage() {
		return this.patientimage;
	}

	public void setPatientimage(byte[] patientimage) {
		this.patientimage = patientimage;
	}

	public String getPatientlastname() {
		return this.patientlastname;
	}

	public void setPatientlastname(String patientlastname) {
		this.patientlastname = patientlastname;
	}

	public String getPatientname() {
		return this.patientname;
	}

	public void setPatientname(String patientname) {
		this.patientname = patientname;
	}

	public String getPatientsex() {
		return this.patientsex;
	}

	public void setPatientsex(String patientsex) {
		this.patientsex = patientsex;
	}

	public String getPatienttitle() {
		return this.patienttitle;
	}

	public void setPatienttitle(String patienttitle) {
		this.patienttitle = patienttitle;
	}

	public int getPhone() {
		return this.phone;
	}

	public void setPhone(int phone) {
		this.phone = phone;
	}

	public List<MedicalReport> getMedicalReports() {
		return this.radioreports;
	}

	public void setMedicalReports(List<MedicalReport> radioreports) {
		this.radioreports = radioreports;
	}

	public MedicalReport addRadioreport(MedicalReport radioreport) {
		getMedicalReports().add(radioreport);
		radioreport.setPatient(this);
		return radioreport;
	}

	public MedicalReport removeRadioreport(MedicalReport radioreport) {
		getMedicalReports().remove(radioreport);
		radioreport.setPatient(null);

		return radioreport;
	}

	public long getCnamID() {
		return this.numMatr;
	}

	public void setCnamID(long numMatr) {
		this.numMatr = numMatr;
	}

	public String getCnamType() {
		return this.type;
	}

	public void setCnamType(String type) {
		this.type = type;
	}

	public Date getCnamValidityDate() {
		return this.validityDate;
	}

	public void setCnamValidityDate(Date validityDate) {
		this.validityDate = validityDate;
	}

	public String getpatientID() {
		return this.idpatient;
	}

	public void setpatientUseFullNotes(String useFNotes) {
		this.usefullNotes = useFNotes;
	}

	public String getpatientUsefullNotes() {
		return this.usefullNotes;
	}

	public void setrdvDate(String rdvDates) {
		DateFormat dateFormat = new SimpleDateFormat(Common.DATE_FORMAT);
		Date date;
		try {
			date = dateFormat.parse(rdvDates);
			this.rdvdate = date;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	public String getrdvDate() {
		DateFormat dateFormat = new SimpleDateFormat(Common.DATE_FORMAT);
		String rdvDateString = null;
		if (rdvdate != null)
			rdvDateString = dateFormat.format(rdvdate);
		return rdvDateString;
	}

}